Ext.namespace('VAS');
/**
 * 审核步骤弹出窗口中的表格窗口
 * @param {} $config
 */
VAS.AuditSelectGrid = function($config) {
	var _this = this;
	this.config = $config;
	VAS.AuditSelectGrid.superclass.constructor.call(this, $config);
};

Ext.extend(VAS.AuditSelectGrid,Ext.grid.GridPanel,{
	id:"AuditSelectGrid",
	initComponent : function() {
		var _this=this;		
		_this.ds=new Ext.data.Store({
			id:Global.STD_GRID_STORE.id,
            url:"admin/audit/auditStep!listUser.action",
			reader : new Ext.data.JsonReader(),
			params:{start:0, limit:10}
		});
		_this.detailWin={};		

		var config = {
			viewConfig : {
				forceFit : true
			},
			enableColLock : false,
			loadMask : true,
			border : false,
			stripeRows : true,
			columns : [],
			record:_this.record,
			bbar: new Ext.PagingToolbar({
	            pageSize: 10,
	            store: _this.ds,
	            displayInfo: true,
	            displayMsg: '第 {0} - {1} 条,共 {2}条',
	            emptyMsg: "没有数据"
        	})
		};
			
		Ext.apply(this, config);
		Ext.apply(this.initialConfig, config);
		VAS.AuditSelectGrid.superclass.initComponent.apply(this, arguments);
	},
	onRender : function(ct, position) {
		var _this=this;
		
		this.colModel.defaultSortable = true;
		VAS.AuditSelectGrid.superclass.onRender.call(this, ct, position);	
		this.store.on('load', function() {
				if (typeof(this.store.reader.jsonData.columns) === 'object') {
					var columns = [];
					if (this.rowNumberer) {
						columns.push(new Ext.grid.RowNumberer());
					}
					if (this.checkboxSelModel) {
						columns.push(new Ext.grid.CheckboxSelectionModel());
					}
					Ext.each(this.store.reader.jsonData.columns, function(column) {
						//不显示ID
						if("id" != column.dataIndex){
							columns.push(column);
						}
					});
					/**
					 * Setting column model configuration
					 */
					this.getColumnModel().setConfig(columns);
				}
				/**
				 * Unmasking grid
				 */
				this.el.unmask();
			}, this);

		var _panelId=this.id;
		this.store.load({params:{panelId:_panelId}}); 
		
		var _data=SyncAjax(this.gridUrl,{"panelId":_panelId});	
		_this.callback(_data);
	},
	
	callback:function(_data){
		var _this=this;
	  	var _lisenters=_data.lisenters;
		Ext.each(_lisenters, function(lisenter) {
			_this.on("rowdblclick" , function(_this, rowIndex, e) {
				var selected = _this.getSelectionModel().getSelected();
				var userId = selected.data.id;
				var userName = selected.data.userName;
				_this.record.set('userName',userName);
				_this.record.set('userId',userId);
				Ext.getCmp("auditSelectWindow").close();
			})
		});
	},
	reload:function($params){
		this.store.reload({params:$params});
	}
});

VAS.AuditSelectGridWindow = function($config) {
	var _this = this;
	this.config = $config;
	VAS.AuditSelectGridWindow.superclass.constructor.call(_this,$config);
};
Ext.extend(VAS.AuditSelectGridWindow,VAS.BasicWindow,{
	 initComponent : function() {
	 	var _this = this;
 		var grid = new VAS.AuditSelectGrid({
 			height:_this.config.height,
 			width:_this.config.width,
 			gridUrl : "admin/audit/auditStep!listEvent.action",
			storeUrl : "admin/audit/auditStep!listUser.action",
			rowNumberer : true,
			checkboxSelModel : true	,
			record:_this.record
		});
	 	var config = {
			title: _this.title,
			items :	[grid]
		};
	 	var _config = config || {};	
		Ext.apply(this, _config);
		Ext.apply(this.initialConfig, _config);
		VAS.AuditSelectGridWindow.superclass.initComponent.apply(this, arguments);
	 }
});

Ext.reg('auditSelect-grid',VAS.AuditSelectGridWindow);

